<template>
	<view>
		<view style="width:750upx;height:150upx;line-height:150upx;text-align:center;">拍摄/上传您的营业执照</view>
		
		<view class="photo_head">
			<view @tap="certificat()" class="bg_img_h" style="position:relative;">
				<image src="../../static/camera.png"></image>
				<view>点击拍摄/上传营业执照</view>
				<image style="position:absolute;top:0;left:0;width:100%;height:100%;" v-if="certification" :src="certification"></image>
			</view>
		</view>
		<view class="submit" @click="submitup()">
			<view>提交</view>
		</view>
	</view>
</template>

<script>
	import request from '@/common/lib/request.js'
	export default {
		data() {
			return {
				baseUrl:request.common.baseUrl,
				certification:''
			}
		},
		onLoad:function(){
			if(uni.getStorageSync('keyCertification')){
				this.certification=uni.getStorageSync('keyCertification')
			}
			
		},
		methods: {
			certificat:function(){
				var that=this
				uni.chooseImage({
					count: 1,
					sizeType:['copressed'],
					success(res) {
						that.certification=res.tempFilePaths[0]
						uni.setStorageSync('keyCertification',res.tempFilePaths[0])
						//因为有一张图片， 输出下标[0]， 直接输出地址
						var imgFiles = res.tempFilePaths[0]
						// 上传图片
						// 做成一个上传对象
						var uper = uni.uploadFile({
							// 需要上传的地址
							url:that.baseUrl+'/api/agent/tupload?token='+uni.getStorageSync('keyToken'),
							// filePath  需要上传的文件
							filePath: imgFiles,
							name: 'file',
							success(res1) {
								// 显示上传信息
								uni.setStorageSync('keyCertificat_img',JSON.parse(res1.data).photo)
							}
						});
					}
				})
			},
			submitup:function(){
				if(uni.getStorageSync('keyCertificat_img')){
					uni.navigateBack({
						delta:1
					})
				}else{
					uni.showToast({
						icon:'none',
						title:'请上传营业执照'
					})
				}
			}
		}
	}
</script>

<style>
page{
	background-color: #ffffff;
}
.photo_head{
	width:450upx;
	height:250upx;
	padding:25upx 150upx;
}
.bg_img_h{
	width:450upx;
	height:250upx;
	/* background-image:url('../../static/head.png'); */
	border:1px dashed #eee;
	background-size:450upx 250upx;
	text-align:center;
}
.bg_img_h image{
	width:80upx;
	height:80upx;
	margin-top:45upx;
	margin-bottom:10upx;
}
.photo_emblem{
	width:450upx;
	height:250upx;
	padding:25upx 150upx;
}
.bg_img_e{
	width:450upx;
	height:250upx;
	background-image:url('../../static/emblem.png');
	background-size:450upx 250upx;
	text-align:center;
}
.bg_img_e image{
	width:80upx;
	height:80upx;
	margin-top:45upx;
	margin-bottom:10upx;
}
.submit{
	margin-top:50upx;
	text-align:center;
}
.submit view{
	background-color:#ff6101;
	color:#FFFFFF;
	font-size:28upx;
	width:650upx;
	height:80upx;
	line-height:80upx;
	margin:auto;
	border-radius:40upx;
}
</style>
